import { Router } from "express"
import { IcallbackFn, Ioracle } from "../../types"

export default (router: Router, oracle: Ioracle, callbackFn: IcallbackFn) => {
  //抓取用餐率
  router.post("/getCanteenRate", (req, res) => {
    const { month } = req.body
    let sql = " select day_type,meal_type "
    sql +=
      " ,to_char(duty_date,'mm')||'月'||to_char(duty_date,'dd')||'日' duty_date "
    sql += " ,round(dinner_cnt/decode(work_cnt,0,1,work_cnt),4) * 100 rate,dinner_cnt,work_cnt "
    sql += " from xx_g00_canteen_data_rate "
    sql += " where duty_date >= to_date('" + month + "'||'-01','yyyy-mm-dd') "
    sql += " and duty_date <= last_day(to_date('" + month + "','yyyy-mm')) "
    sql += " order by duty_date,seq "
    callbackFn( res, oracle.connHrm,{sql})
  })

  //by批次用餐率
  router.post("/getCanteenBatchRate", (req, res) => {
    const { day } = req.body
    let sql =
      " select meal_type,duty_time,org_code,dinner_cnt,to_char(duty_date,'yyyymmdd') duty_date "
    sql += " ,batch_type from xx_g00_canteen_data_batch_rate "
    sql += " where 1 = 1 "
    sql += " and duty_date = to_date('" + day + "','yyyy/mm/dd') "
    sql +=
      " order by decode(meal_type,'早餐','1','中餐','2','晚餐','3','夜宵','4') "
    sql += " ,to_number(replace(replace(batch_type,'第',''),'批','')),org_code "

    callbackFn( res, oracle.connHrm,{sql})
  })

  return router
}
